from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn import svm, datasets
import matplotlib.pyplot as plt
import numpy as np


def main():
    iris = datasets.load_iris()
    X = iris.data
    y = iris.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, random_state=0)
    linear = svm.SVC(kernel='linear', C=1,
                     decision_function_shape='ovo').fit(X_train, y_train)

    rbf = svm.SVC(kernel='rbf', gamma=1, C=1,
                  decision_function_shape='ovo').fit(X_train, y_train)

    poly = svm.SVC(kernel='poly', degree=3, C=1,
                   decision_function_shape='ovo').fit(X_train, y_train)

    sig = svm.SVC(kernel='sigmoid', C=1,
                  decision_function_shape='ovo').fit(X_train, y_train)

    # h = 0.01
    # X_min, X_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    # y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    # xx, yy = np.meshgrid(np.arange(X_min, X_max, h), np.arange(y_min, y_max, h))
    # titles = ['Linear kernel', 'RBF kernel', 'Polynomial kernel', 'Sigmoid kernel']

    # for i, clf in enumerate((linear, rbf, poly, sig)):
    #     plt.subplot(2, 2, i + 1)
    #     plt.subplots_adjust(wspace=0.4, hspace=0.4)
    #     Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
    #
    #     Z = Z.reshape(xx.shape)
    #     plt.contourf(xx, yy, Z, cmap=plt.cm.PuBuGn, alpha=0.7)
    #
    #     plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.PuBuGn, edgecolors='grey')
    #
    #     plt.xlabel('Sepal length')
    #     plt.ylabel('Sepal width')
    #     plt.xlim(xx.min(), xx.max())
    #     plt.ylim(yy.min(), yy.max())
    #     plt.xticks(())
    #     plt.yticks(())
    #     plt.title(titles[i])

        # plt.show()

    linear_pred = linear.predict(X_test)
    poly_pred = poly.predict(X_test)
    rbf_pred = rbf.predict(X_test)
    sig_pred = sig.predict(X_test)

    acc_linear = linear.score(X_test, y_test)
    acc_poly = poly.score(X_test, y_test)
    acc_rbf = rbf.score(X_test, y_test)
    acc_sig = sig.score(X_test, y_test)

    print('Linear Acc:', acc_linear)
    print('Polynomial Acc:', acc_poly)
    print('RBF Acc:', acc_rbf)
    print('Sig Acc:', acc_sig)


    print()


if __name__ == '__main__':
    main()
